function [ PercentageRatio, ClassificationOutput ] = SvmOneToOne( DataSet, Gamma )
%SVMONETOONE Summary of this function goes here
%   Detailed explanation goes here

[Samples, Labels, Classes] = LoadTrainData(DataSet);

ClassCounts = zeros(1, Classes);
ClassFilter = cell(1, Classes);

SamplesSize = size(Samples);
SamplesCount = SamplesSize(2);

for i = 1:1:Classes
    SelectedSamples = Labels(1,:) == i;
    ClassFilter{i} = Samples(:, SelectedSamples);
end

AlphaY = cell(Classes, Classes);
SVs = cell(Classes, Classes);
Bias = cell(Classes, Classes);
Parameters = cell(Classes, Classes);
nSV = cell(Classes, Classes);
nLabel = cell(Classes, Classes);

for i = 1:1:Classes-1
    iClass = ClassFilter{i};
    iLabels = ones(1, size(iClass, 2));
    
    for j = i+1:1:Classes
        jClass = ClassFilter{j};
        jLabels = zeros(1, size(jClass, 2));
        
        MergedClasses = [iClass jClass];
        MergedLabels = [iLabels jLabels];
        
        [AlphaY{i,j}, SVs{i,j}, Bias{i,j}, Parameters{i,j}, nSV{i,j}, nLabel{i,j}] = RbfSVC(MergedClasses, MergedLabels, Gamma);
    end
end

[Samples, Labels] = LoadTestData(DataSet);
SamplesCount = size(Samples, 2);

PredictedLabels = cell(Classes, Classes);
DecisionValues = cell(Classes, Classes);

for i = 1:1:Classes-1
    for j = i+1:1:Classes
        [PredictedLabels{i,j}, DecisionValues{i,j}] = SVMClass(Samples, AlphaY{i,j}, SVs{i,j}, Bias{i,j}, Parameters{i,j}, nSV{i,j}, nLabel{i,j});
    end
end

ClassificationOutput = zeros(1, SamplesCount);
TotalHitCount = 0;

for s = 1:1:SamplesCount
    Voting = zeros(1, Classes);
    
    for i = 1:1:Classes-1
        for j = i+1:1:Classes
            predict = PredictedLabels{i, j}(s);
            if predict == 1
                Voting(i) = Voting(i) + 1;
            else
                Voting(j) = Voting(j) + 1;
            end
        end
    end
    
    [C, I] = max(Voting(1,:));
    ClassificationOutput(s) = I;
    
    if I == Labels(s)
        TotalHitCount = TotalHitCount + 1;
    end
end

PercentageRatio = (TotalHitCount/SamplesCount)*100;

end

